package com.zzc.fwzpxt.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zzc.fwzpxt.entity.RegAddress;
import com.zzc.fwzpxt.entity.RegCapital;
import com.zzc.fwzpxt.service.IRegCapitalService;
import com.zzc.common.controller.BaseController;
import com.zzc.common.result.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 注册资本 reg_capital 前端控制器
 * </p>
 *
 * @author XiaoBingBy
 * @since 2017-09-26
 */
@Controller
@RequestMapping("/admin/regCapital")
public class RegCapitalController extends BaseController {

    @Autowired
    private IRegCapitalService iRegCapitalService;

    @GetMapping("/list")
    public String list() {
        return blogPath + "reg_capital/list";
    }

    @ResponseBody
    @RequestMapping("/getList")
    public List<RegCapital> getList() {
        EntityWrapper<RegCapital> wrapper = new EntityWrapper<>();
        wrapper.eq("status", 1);
        wrapper.orderBy("capital", true);
        List<RegCapital> regCapitals = iRegCapitalService.selectList(wrapper);
        return regCapitals;
    }

    /**
     * 添加修改
     * @param regCapital
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save")
    public JsonResult save(RegCapital regCapital) {
        if (regCapital.getId() == null) {
            return iRegCapitalService.insert(regCapital) ? renderSuccess("添加成功") : renderError("添加失败");
        } else {
            return iRegCapitalService.updateById(regCapital) ? renderSuccess("修改成功") : renderError("修改失败");
        }
    }

}
